home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr09 / vstsrc.zip / COLORS.C < prev    next >
C/C++ Source or Header  |  1995-01-25  |  7KB  |  257 lines

  1. /*
  2.  * VersaTrack Copyright (c) 1993, 1994 Siamack Navabpour. All Rights Reserved.
  3.  *
  4.  * Permission is hereby granted to copy, modify and distribute VersaTrack
  5.  * in whole, or in part, for educational, non-profit and non-commercial use
  6.  * only, free of charge or obligation, and without agreement, provided that
  7.  * all copyrights and restrictions noted herein are observed and followed, and
  8.  * additionally, that this and all other copyright notices listed herein
  9.  * appear unaltered in all copies and in all derived work.
  10.  *
  11.  * This notice shall not in any way void or supersede any of the other authors
  12.  * rights or privileges.
  13.  *
  14.  * VersaTrack IS PRESENTED FREE AND "AS IS", WITHOUT ANY WARRANTY OR SUPPORT.
  15.  * YOU USE IT AT YOUR OWN RISK. The author(s) shall not be liable for any
  16.  * direct, indirect, incidental, or consequential damage, loss of profits or
  17.  * other tangible or intangible losses or benefits, arising out of or related
  18.  * to its use. VersaTrack carries no warranty, explicit or implied, including
  19.  * but not limited to those of merchantablity and fitness for a particular
  20.  * purpose.
  21.  *
  22.  * Siamack Navabpour, 12342 Hunter's Chase Dr. Apt. 2114, Austin, TX 78729.
  23.  * sia@bga.com or sia@realtime.com.
  24.  */
  25.  
  26.  
  27. #pragma  check_stack(off)
  28.  
  29. #include <windows.h>
  30. #include "resource.h"
  31. #include "vstdefs.h"
  32. #include "vsttype.h"
  33. #include "vstextrn.h"
  34.  
  35.  
  36. #define NI 16
  37. static UINT bid[NI] = {
  38.     IDC_CC_0,  IDC_CC_1,  IDC_CC_2,  IDC_CC_3,
  39.     IDC_CC_4,  IDC_CC_5,  IDC_CC_6,  IDC_CC_7,
  40.     IDC_CC_8,  IDC_CC_9,  IDC_CC_10, IDC_CC_11,
  41.     IDC_CC_12, IDC_CC_13, IDC_CC_14, IDC_CC_15,
  42. };
  43.  
  44. #define SET_PEN     0
  45. #define SET_BRUSH   1
  46. #define SET_TEXT    2
  47. #define IDT_FLASH    32000
  48.  
  49. static int   which, ipen, ibrush, itext;
  50. static UINT  flash = (UINT)-1;
  51. static BOOL     flash_state = TRUE;
  52.  
  53. static void
  54. SqrButton(HWND hwnd, UINT id)
  55. {
  56.     if (id != IDC_CC_BRUSH)
  57.         setbutton(hwnd, IDC_CC_BRUSH, FALSE);
  58.     if (id != IDC_CC_TEXT)
  59.         setbutton(hwnd, IDC_CC_TEXT, FALSE);
  60.     if (id != IDC_CC_PEN)
  61.         setbutton(hwnd, IDC_CC_PEN, FALSE);
  62.         
  63.     setbutton(hwnd, id, TRUE);
  64. }
  65.  
  66. static void
  67. DlgButtons(HWND hwnd, int color)
  68. {
  69.     int i;    
  70.     for (i=0; i < 16; i++) {
  71.         if (color == i)
  72.               flash = bid[i];
  73.         SendDlgItemMessage(hwnd, bid[i], BM_SETSTATE,
  74.             (WPARAM) ((color == i) ? TRUE : FALSE), (LPARAM) 0);
  75.     }
  76. }
  77.  
  78.  
  79. static int
  80. checkbuttons(hwnd, wParam)
  81. HWND hwnd;
  82. WPARAM wParam;
  83. {
  84.     int i, cmd;
  85.  
  86.     cmd = LOWORD(wParam);
  87.  
  88.     switch (cmd) {
  89.     case IDOK:
  90.     case IDCANCEL:
  91.         return cmd;
  92.     
  93.     case IDC_CC_PEN:
  94.         which = SET_PEN;
  95.         SqrButton(hwnd, IDC_CC_PEN);
  96.         DlgButtons(hwnd, ipen);
  97.         return -1;
  98.  
  99.     case IDC_CC_BRUSH:
  100.         which = SET_BRUSH;
  101.         SqrButton(hwnd, IDC_CC_BRUSH);
  102.         DlgButtons(hwnd, ibrush);
  103.         return -1;
  104.  
  105.     case IDC_CC_TEXT:
  106.         which = SET_TEXT;
  107.         SqrButton(hwnd, IDC_CC_TEXT);
  108.         DlgButtons(hwnd, itext);
  109.         return -1;
  110.  
  111.     default:        
  112.         break;
  113.     }
  114.     if (HIWORD(wParam) != BN_CLICKED)
  115.         return cmd;
  116.  
  117.     for (i=0; i<16; i++) {
  118.         if ((UINT)cmd == (UINT)bid[i]) {
  119.             if (which == SET_PEN)
  120.                  DlgButtons(hwnd, ipen = i);
  121.             else if (which == SET_BRUSH)
  122.                  DlgButtons(hwnd, ibrush = i);
  123.             else
  124.                  DlgButtons(hwnd, itext = i);
  125.         }
  126.     }
  127.     return -1;
  128. }
  129.        
  130. static int
  131. findex(UINT id)
  132. {
  133.     int i;
  134.     for (i=0; i<NI; i++)
  135.         if (id == bid[i])
  136.             return i;
  137.     return -1;
  138. }
  139.  
  140. static void
  141. DrawButton(LPARAM lParam)
  142. {
  143.     int c;
  144.     LPDRAWITEMSTRUCT dip = (LPDRAWITEMSTRUCT) lParam;
  145.     
  146.     if (findex(dip->CtlID) == (c = CBLACK))
  147.         c = CWHITE;
  148.  
  149.     SelectObject(dip->hDC, hDrawPen[c]);
  150.     FillRect(dip->hDC, &dip->rcItem, hDrawBrush[8]);
  151.     SelectObject(dip->hDC, hDrawBrush[findex(dip->CtlID)]);
  152.  
  153.     if (!(dip->itemState & ODS_SELECTED))
  154.         Ellipse(dip->hDC, dip->rcItem.left+3, dip->rcItem.top+3,
  155.             dip->rcItem.right-3, dip->rcItem.bottom-3);
  156.     else
  157.         Ellipse(dip->hDC, dip->rcItem.left, dip->rcItem.top,
  158.             dip->rcItem.right, dip->rcItem.bottom);
  159.  
  160.      if (dip->itemState & ODS_FOCUS)
  161.         Ellipse(dip->hDC, dip->rcItem.left+5, dip->rcItem.top+5,
  162.             dip->rcItem.right-5, dip->rcItem.bottom-5);
  163. }
  164.  
  165. static
  166. BOOL CALLBACK ColorsProc(hwnd, message, wParam, lParam)
  167. HWND hwnd;
  168. UINT message;
  169. WPARAM wParam;
  170. LPARAM lParam;
  171. {
  172.     POINT *p;
  173.     int cmd;
  174.     extern POINT *DialogPos(HWND, HWND);
  175.         
  176.     if (message == WM_MOUSEMOVE)
  177.         return TRUE;
  178.             
  179.     switch(message) {
  180.     case WM_INITDIALOG:
  181.         p = DialogPos(Gwnd, hwnd);
  182.         SqrButton(hwnd, IDC_CC_PEN);
  183.         which = SET_PEN;
  184.         DlgButtons(hwnd, ipen = PenColor);
  185.         ibrush = BrushColor;
  186.         itext = TextColor;
  187.         SetTimer(hwnd, IDT_FLASH, (DWORD) 261, (TIMERPROC) NULL);
  188.         SetWindowPos(hwnd, 0, (int)p->x, (int)p->y, 0, 0,
  189.             SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
  190.         return TRUE;
  191.                 
  192.     case WM_TIMER:
  193.          if (LOWORD(wParam) == IDT_FLASH && flash != 0xffffffff)
  194.             SendDlgItemMessage(hwnd, (UINT)flash, BM_SETSTATE,
  195.                 (WPARAM) (flash_state = !flash_state), (LPARAM) 0);
  196.         return TRUE;
  197.             
  198.     case WM_DRAWITEM:
  199.         DrawButton(lParam);
  200.         return TRUE;
  201.                 
  202.     case WM_COMMAND:
  203.         if ((cmd = checkbuttons(hwnd, wParam)) == -1)
  204.             return TRUE;
  205.  
  206.         if (cmd == IDOK) {
  207.             KillTimer(hwnd, IDT_FLASH);
  208.             EndDialog(hwnd, IDOK);
  209.             return TRUE;
  210.         }
  211.         if (cmd == IDCANCEL) {
  212.             KillTimer(hwnd, IDT_FLASH);
  213.             EndDialog(hwnd, IDCANCEL);
  214.             return TRUE;
  215.         }
  216.         break;
  217.  
  218.     case WM_CTLCOLORDLG:
  219.         ColorSet(wParam, CBLACK, 8);
  220.         return (BOOL) hDrawBrush[8];
  221.                 
  222.     case WM_CTLCOLORSTATIC:
  223.     case WM_CTLCOLORMSGBOX:
  224.     case WM_CTLCOLORBTN:
  225.         ColorSet(wParam, CBLACK, 8);
  226.         return (BOOL) hDrawBrush[8]; 
  227.  
  228.     default:
  229.         break;
  230.                 
  231.     }
  232.     return FALSE;
  233. }
  234.  
  235. /*
  236.  * On return, PenColor, BrushColor and TextColor will be set
  237.  * according to user's selection, or remain unchanged if user CANCELed.
  238.  */
  239.  
  240. void
  241. SetColors()
  242. {
  243.     int result;
  244.  
  245.     if (running) {
  246.         usermsg("Cannot change colors while Real-time Display is running");
  247.         return ;
  248.     }
  249.     result = DialogBox(NULL, MAKEINTRESOURCE(IDD_COLORS), Gwnd, ColorsProc);
  250.     if (result == IDOK) {
  251.         PenColor = ipen;
  252.         BrushColor = ibrush;
  253.         TextColor = itext;
  254.     }
  255. }
  256.  
  257.